package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

    @Autowired
    private ItemMapper itemMapper;
    @Override
    public Page<Item> selectPage(Page<Item> itemPage, LambdaQueryWrapper<Item> wrapper) {
        Page<Item> page = itemMapper.selectPage(itemPage, wrapper);
        return page;
    }

    @Override
    public void stock(Long itemId, Integer num) {
        Item item = getById(itemId);
        item.setStock(item.getStock() - num);
        updateById(item);
    }


}
